import request from '@/utils/request'

// 上传图片
export function upload(data) {
  const formData = new FormData()

  formData.append('file', data)
  return request('/Common/Upload?' + new Date(), 'POST', formData)
}

// 验证是否重复
export function duplicateCheck(url, methods, value) {
  return request(url, methods, value)
}

// 登录
export function login(value) {
  return request('/Auth/Login', 'POST', value)
}

// 请求验证码
export function getValidationCode() {
  return request('/Auth/GetValidationCode', 'GET', null)
}

// 用户
export function user(methods, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/User/' + data.id
    value = data.value
  } else {
    url = '/User/Search'
    value = data
  }
  return request(url, methods, value)
}

// 修改当前用户密码
export function changePassword(methods, data) {
  let url = '/Auth/ChangePassword'
  return request(url, methods, data)
}

// 员工相关
export function employee(methods, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/Employee/' + data.id
    value = data.value
  } else {
    url = '/Employee/Search'
    value = data
  }
  return request(url, methods, value)
}

export function employeeExport(methods, data) {
  var url = '/Employee/ExcelFile'
  var value = data
  return request(url, methods, value)
}

// 下载模板
export function employees() {
  return request('/files/employees.xlsx?v=' + new Date(), 'GET', null)
}

// 员工禁用启用
export function setEmployee(methods, data) {
  let url = '/Employee/SetEnable'
  return request(url, methods, data)
}

// 员工离职
export function quitEmployee(data) {
  return request('/Employee/SetSeperate', 'POST', data)
}

// 部门相关
export function department(methods, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/Department/' + data.id
    value = data.value
  } else {
    url = '/Department/Search'
    value = data
  }
  return request(url, methods, value)
}
// 请求部门最大ID
export function getAlertCount() {
  return request('/TunnelRealTime/GetAlertCount', 'get', null)
}
// 请求部门最大ID
export function getDepartmentMaxId() {
  return request('/Department/GetMaxId', 'get', null)
}
// 请求职位最大ID
export function getJobMaxId() {
  return request('/Job/GetMaxId', 'get', null)
}
// 请求工种最大ID
export function getWorkMaxId() {
  return request('/Work/GetMaxId', 'get', null)
}

// 职位管理
export function job(methods, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/Job/' + data.id
    value = data.value
  } else {
    url = '/Job/Search'
    value = data
  }
  return request(url, methods, value)
}

// 工种管理
export function work(methods, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/Work/' + data.id
    value = data.value
  } else {
    url = '/Work/Search'
    value = data
  }
  return request(url, methods, value)
}

// 车辆管理
export function car(methods, data, bln) {
  let url = ''
  let value = null
  if (bln) {
    url = '/Car/' + data.id
    value = data.value
  } else {
    url = '/Car/Search'
    value = data
  }
  return request(url, methods, value)
}

// 区域管理
export function area(methods, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/Area/' + data.id
    value = data.value
  } else {
    url = '/Area/Search'
    value = data
  }
  return request(url, methods, value)
}
// 获得最大区域ID
export function areaMaxId() {
  return request('/Area/GetMaxId', 'get', null)
}

// 基站
export function baseStation(methods, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/BaseStation/' + data.id
    value = data.value
  } else {
    url = '/BaseStation/Search'
    value = data
  }
  return request(url, methods, value)
}

// 门禁
export function autoGate(methods, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/AutoGate/' + data.id
    value = data.value
  } else {
    url = '/AutoGate/Search'
    value = data
  }
  return request(url, methods, value)
}

// 传感器基站
export function sensorStation(methods, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/EnvironmentTrackingSetting/' + data.id
    value = data.value
  } else {
    url = '/EnvironmentTrackingSetting/Search'
    value = data
  }
  return request(url, methods, value)
}

// 传感器
export function sensorOne(methods, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/Sensor/' + data.id
    value = data.value
  } else {
    url = '/Sensor/Search'
    value = data
  }
  return request(url, methods, value)
}

// 视频
export function videoInterface(methods, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/Video/' + data.id
    value = data.value
  } else {
    url = '/Video/Search'
    value = data
  }
  return request(url, methods, value)
}

// 进出洞记录
export function tunnelIORecord(methods, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/TunnelIORecord/' + data.id
    value = data.value
  } else {
    url = '/TunnelIORecord/Search'
    value = data
  }
  return request(url, methods, value)
}
// 进出洞记录
export function clearPeople(data) {
  let url = ''
  let value = null
  url = '/Location/ClearPeople/' + data.id
  value = data.value
  return request(url, 'POST', value)
}

// 实时定位
export function realtimeLocation(methods, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/RealtimeLocation/' + data.id
    value = data.value
  } else {
    url = '/RealtimeLocation/Search'
    value = data
  }
  return request(url, methods, value)
}

// 安全帽报警
export function safetyCatTracking(methods, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/SafetyCatTracking/' + data.id
    value = data.value
  } else {
    url = '/SafetyCatTracking/Search'
    value = data
  }
  return request(url, methods, value)
}

// 轨迹回放
export function path(methods, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/Path/' + data.id
    value = data.value
  } else {
    url = '/Path/Search'
    value = data
  }
  return request(url, methods, value)
}

// 工点信息
export function tunnel(methods, data) {
  let url = ''
  let value = null
  methods = methods.toLocaleUpperCase()
  if (methods === 'POST') {
    // 新增
    url = '/Tunnel'
    value = data
  } else if (methods === 'GET') {
    // 查询
    url = '/Tunnel/firstOne'
    value = data
  } else {
    // 编辑
    url = '/Tunnel/' + data.id
    value = data.value
  }
  return request(url, methods, value)
}

// 操作日志
export function actionLog(methods, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/ActionLog/' + data.id
    value = data.value
  } else {
    url = '/ActionLog/Search'
    value = data
  }
  return request(url, methods, value)
}

// 人脸识别设备设置
export function faceDetectSetting(methods, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    // 人脸识别设置和查询
    url = '/FaceDetectSetting/' + data.id
    value = data.value
  } else {
    // 拍照
    url = '/FaceDetectSetting/Search'
    value = data
  }
  return request(url, methods, value)
}

// 人脸识别
export function faceDetect(methods, value = '') {
  let url = ''
  methods = methods.toLocaleUpperCase()
  if (methods === 'GET' || methods === 'PUT') {
    // 人脸识别设置和查询
    url = '/FaceDetect/Device/Settings'
  } else {
    // 拍照
    url = '/FaceDetect/Device/TakeImage'
  }
  return request(url, methods, value)
} // 人脸识别
export function SyncFaceDetectData(methods, value = '') {
  let url = ''
  methods = methods.toLocaleUpperCase()
  url = '/Employee/SyncPerson'
  return request(url, methods, value)
}

// 请求人员ID
export function getMaxId() {
  return request('/Employee/GetMaxId', 'get', null)
}

// 删除人员ID
export function delMaxId(value) {
  return request('/FaceDetect/Person/' + value, 'delete', null)
}

// 启用禁用人脸识别
export function distinguish(methods, id) {
  let url = ''
  if (methods === 'open') {
    url = '/FaceDetect/Person/Enable/' + id
  } else if (methods === 'close') {
    url = '/FaceDetect/Person/Disable/' + id
  }
  return request(url, 'post', null)
}

// 进出洞记录
export function faceCheck(data) {
  let url = ''
  let value = null
  url = '/FaceDetect/Device/CheckImage'
  value = data
  return request(url, 'POST', value)
}

// 考勤设置
export function attendance(methods, data) {
  let url = ''
  let value = ''
  methods = methods.toLocaleUpperCase()
  if (methods === 'GET') {
    url = '/AttendanceSetting/firstOne'
  } else if (methods === 'PUT') {
    url = '/AttendanceSetting/' + data.id
    value = data.value
  } else if (methods === 'POST') {
    url = '/AttendanceSetting'
    value = data
  }
  return request(url, methods, value)
}

// 报警设置
export function warningSetting(methods, data) {
  let url = ''
  let value = ''
  methods = methods.toLocaleUpperCase()
  if (methods === 'GET') {
    url = '/WarningSetting/firstOne'
  } else if (methods === 'PUT') {
    url = '/WarningSetting/' + data.id
    value = data.value
  } else if (methods === 'POST') {
    url = '/WarningSetting'
    value = data
  }
  return request(url, methods, value)
}

// 自定义工具栏
export function customNavigationBar(methods, data, bln = false) {
  let url = ''
  let value = ''
  methods = methods.toLocaleUpperCase()
  if (methods === 'PUT') {
    url = '/CustomNavigationBar'
    value = data
  } else if (methods === 'POST') {
    if (bln) {
      url = '/CustomNavigationBar/Batch'
      value = data
    } else {
      url = '/CustomNavigationBar/Search'
      value = data
    }
  }
  return request(url, methods, value)
}

// 环境监测
export function environmentTracking(methods, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/EnvironmentTracking/' + data.id
    value = data.value
  } else {
    url = '/EnvironmentTracking/Search'
    value = data
  }
  return request(url, methods, value)
}

// 隧道示意图
export function tunnelRealTime(value) {
  return request('/TunnelRealTime', 'get', { includeGate: value })
}
// 考勤统计
export function attendanceList(methods, data, bln) {
  let url = ''
  let value = null
  // methods = methods.toLocaleUpperCase()
  // if (methods === 'GET') {
  //   url = '/Attendance/List'
  //   value = data
  // }
  if (bln) {
    url = '/Attendance/' + data.id
    value = data.value
  } else {
    url = '/Attendance/Search'
    value = data
  }
  return request(url, methods, value)
}

// 平台设置 默认数据
export function setting(methods, data) {
  let url = ''
  let value = null
  methods = methods.toLocaleUpperCase()
  if (methods === 'GET') {
    // 默认数据
    url = '/Setting/firstOne'
    value = data
  } else if (methods === 'PUT') {
    url = '/Setting/' + data.id
    value = data.value
  }
  return request(url, methods, value)
}

// 报警消息标记为已读
export function alertHandler(type, ids) {
  let url = `/Alert/Read/${type}/${ids}`
  return request(url, 'post', '')
}

// 安全帽管理
export function safetyCatSetting(methods, data) {
  let url = ''
  let value = null
  methods = methods.toLocaleUpperCase()
  if (methods === 'GET') {
    url = '/SafetyCatSetting/firstOne'
    value = data
  } else if (methods === 'PUT') {
    url = 'SafetyCatSetting/' + data.id
    value = data.value
  }
  return request(url, methods, value)
}

// 报警消息 超员
export function alertOverMan(methods, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/AlertOverMan/' + data.id
    value = data.value
  } else {
    url = '/AlertOverMan/Search'
    value = data
  }
  return request(url, methods, value)
}

// 报警消息 超时
export function alertOverTime(methods, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/AlertOverTime/' + data.id
    value = data.value
  } else {
    url = '/AlertOverTime/Search'
    value = data
  }
  return request(url, methods, value)
}

// 报警消息 环境监测
export function alertSensor(methods, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/AlertSensor/' + data.id
    value = data.value
  } else {
    url = '/AlertSensor/Search'
    value = data
  }
  return request(url, methods, value)
}

// 报警消息 视频报警
export function alertVideo(methods, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/AlertVideo/' + data.id
    value = data.value
  } else {
    url = '/AlertVideo/Search'
    value = data
  }
  return request(url, methods, value)
}

// 导入共享软件包
export function SharedPackage(data) {
  return request(`/Employee/ImportSharedEmployee?fileName=${data}`, 'GET', null)
}
// 批量导入员工
export function importEmployee(data) {
  return request(`/Employee/ImportEmployee?fileName=${data}`, 'GET', null)
}
// 批量导入车辆
export function importCar(data) {
  return request(`/Car/ImportCar?fileName=${data}`, 'GET', null)
}

// 设备图像设置
export function parameter(methods, value) {
  let url = ''
  methods = methods.toLocaleUpperCase()
  if (methods === 'GET') {
    url = '/Parameter/parameterName'
  } else if (methods === 'PUT') {
    url = '/Parameter'
  }
  return request(url, methods, value)
}

// 人脸识别的照片复制到指定的目录
export function CopyFiles(data) {
  return request(`/Employee/CopyFiles?srcFolder=${data.srcFolder}&targetFolder=${data.targetFolder}`, 'GET', null)
}

// 上传图片
export function upload64(data) {
  const formData = new FormData()

  formData.append('file', data)
  return request('/Common/Upload64', 'POST', formData)
}
